package cn.edu.njust.epms.service.Impl;

import cn.edu.njust.epms.common.R;
import cn.edu.njust.epms.dao.IODao;
import cn.edu.njust.epms.dao.UserDao;
import cn.edu.njust.epms.entity.IORecord;
import cn.edu.njust.epms.entity.UserDetails;
import cn.edu.njust.epms.service.IOService;
import cn.edu.njust.epms.common.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class IOServiceImpl implements IOService {
    @Autowired
    IODao dao;
    @Autowired
    UserDao udao;

    @Override
    public Resp<IORecord> ioReg(IORecord record) {
        String pid = record.getPid();
        UserDetails ud = udao.selectUdByPid(pid);
        if(ud==null)    return Resp.error("请输入正确的身份证！");
        record.setrTime(new Date());
        boolean b = dao.Add(record);
        if (b)
            return Resp.success(record);
        else
            return Resp.error("登记失败！");
    }

    @Override
    public Resp<List<IORecord>> selectByCondition(R r) {
        List<IORecord> list = dao.selectByCondition(r);
        return Resp.success(list);
    }
@Override
    public Resp<String> deleteIORecord(IORecord r){
        Boolean b = dao.deleteIORecord(r);
        if (b)  return Resp.success("删除成功");
        return Resp.error("删除失败！");
    }
}
